package com.yc.star.booksystem.model;

import lombok.Data;

@Data
public class Result<T> {

    private Integer code; // 200: 响应成功 -1: 响应失败
    private String errMsg; // 返回错误信息
    private T data; // 正常接口返回数据

    // 成功时
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(200);
        return result;
    }

    // 失败时
    public static <T> Result<T> fail(T data,String errMsg) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(-1);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setErrMsg(errMsg);
        return result;
    }

}
